home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / web_dev / files / jext-install.exe / {app} / bin / scripts / JavaCounter.jext-script < prev    next >
Encoding:
Text File  |  2001-06-19  |  1.7 KB  |  72 lines

  1. #######################################
  2. # JAVA PURE SOURCE CODE LINES COUNTER #
  3. #######################################
  4. # (C)2000 Romain Guy                  #
  5. # Dawn demonstration                  #
  6. #######################################
  7.  
  8. # tells if we're inside a wing comment
  9. 0 wing ->
  10.  
  11. # builds the array required to check comments
  12. array
  13. "//" addElement
  14. "/*" addElement
  15. "*/" addElement
  16. comments ->
  17.  
  18. # gets file name from user's prompt
  19. "Java source file: " input dup dup dup sourceFile ->
  20.  
  21. # checks if the file exists
  22. if exists not then
  23.   "Source file " swap concat " does not exist !" concat msgBox
  24.   exit
  25. else
  26.   drop
  27. end
  28.  
  29. # open the file
  30. "SOURCE.FILE" openForInput
  31.  
  32. # inits variables
  33. "" line ->
  34. 0 codeLines ->
  35.  
  36. try
  37.   # parses the source code
  38.   while "SOURCE.FILE" isFileAvailable repeat
  39.     "SOURCE.FILE" readLine
  40.  
  41.     if depth 0 > then
  42.       # removes white spaces
  43.       trim line ->
  44.  
  45.       # exits from wing comment
  46.       if wing rcl 1 == then
  47.         if line rcl comments rcl 2 elementAt swap drop endsWith then
  48.           0 wing ->
  49.         end
  50.       else
  51.         # if line begins with '//' we do not count it
  52.         if line rcl comments rcl 0 elementAt swap drop startsWith not
  53.            line rcl size 0 > and then
  54.  
  55.            # checks if we're inside a wing comment
  56.            if line rcl comments rcl 1 elementAt swap drop startsWith then
  57.              line rcl comments rcl 2 elementAt swap drop startsWith not
  58.              wing ->
  59.            else
  60.              codeLines ++
  61.            end
  62.         end
  63.       end
  64.     end
  65.   wend
  66. catch "Cannot read the file " sourceFile rcl concat " !" concat msgBox exit err
  67.  
  68. # displays summary
  69. sourceFile rcl ": " concat codeLines rcl ->str " lines of code" concat concat msgBox
  70.  
  71. # End of script
  72.